const router = require('koa-router')();
const query = require('../db/mysql');
const { getList, addList, editList, delList } = require('../controller/home');
const jwt = require('jsonwebtoken');
const auth = require('../middleware/auth');

//鉴权中间件
const middleware = async (ctx, next) => {
    const { authorization } = ctx.request.header;
    if (authorization) {
        try {
            jwt.verify(token, '1812a');
            await next()
        } catch (error) {
            ctx.body = '效验失败'
        }
    }else{
        ctx.body="你没有权限"
    }

}
//获取列表
router.get('/api/list',middleware,getList);
//添加
router.post('/api/list',middleware,addList);
//编辑
router.put('/api/list',middleware,editList);
//删除
router.delList('/api/list/:id',middleware,delList)
module.exports=router;